﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace apparatus
{
    public partial class frmReceive : Form
    {

        public string getNo()
        {
            return textBox1 .Text ;
        }
        public void setNo(string Name)
        {
            textBox1.Text=Name ;
        }



        public int i=1;
        public frmReceive()
        {
            InitializeComponent();
        }

        private void mainBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.mainBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.db1DataSet);

        }

        private void frmReceive_Load(object sender, EventArgs e)
        {
             dateTimePicker1.CustomFormat = "yyyy-M-d";           
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.MaxDate = DateTime.Today;
            // TODO: 这行代码将数据加载到表“db1DataSet.apparatus_receive_view”中。您可以根据需要移动或移除它。
            this.apparatus_receive_viewTableAdapter.Fill(this.db1DataSet.apparatus_receive_view);
            // TODO: 这行代码将数据加载到表“db1DataSet.main”中。您可以根据需要移动或移除它。
            //this.mainTableAdapter.Fill(this.db1DataSet.main);

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            button1_Click(null, null);
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) button1_Click(null, null);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                this.mainTableAdapter.FillByNo(this.db1DataSet.main, textBox1.Text);
                if (this.db1DataSet.main.Count!= 0)
                {     btnaddtosheet.Enabled = true;
                    txtsheetno.Focus();
                }
            }
        }


        private void button3_Click(object sender, EventArgs e)
        {
 
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Form receivereport = new receiveprint();
            receivereport.ShowDialog();
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void apparatus_receive_viewDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
 
        }

        private void apparatus_receive_viewDataGridView_RowsAdded_1(object sender, DataGridViewRowsAddedEventArgs e)
        {
            RedoSerialNo();
        }

        private void RedoSerialNo()
        {
            for (int i = 0; i < apparatus_receive_viewDataGridView.RowCount; ++i)
            {
                apparatus_receive_viewDataGridView[0, i].Value = i + 1;
            }
        }

        private void apparatus_receive_viewDataGridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            RedoSerialNo();
        }

        private void button4_Click(object sender, EventArgs e)
        {
           
            main_edit main_edit1 = new main_edit();
            main_edit1.textBox1.Text = this.textBox1.Text;
            main_edit1.ShowDialog();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            Form receivereport = new receiveprint();
            receivereport.ShowDialog();
        }

        private void btnaddtosheet_Click(object sender, EventArgs e)
        {
            try
            {
                this.apparatus_receiveTableAdapter1.InsertQuery(
                    txtprivateno.Text,
                    textBox1.Text,
                    Convert.ToString(dateTimePicker1.Value),
                    textBox4.Text,
                    tsoperator.Text,
                    tbmemo.Text);
                this.apparatus_receive_viewTableAdapter.Fill(this.db1DataSet.apparatus_receive_view);

                textBox1.Text = "";
                btnaddtosheet.Enabled = false;
                textBox1.Focus();
            }
            catch { }
        }

        private void txtsheetno_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) txtprivateno.Focus();
        }

        private void txtprivateno_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) tbmemo.Focus();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tbmemo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) btnaddtosheet.Focus();
        }

 






    }
}
